package com.jemmyee.core.utils;

import java.util.ArrayList;
import java.util.List;

public class ReportUtils {

	
	
	public static List<List<String>> reconfigurationForReport(List<List<String>> results,List<List<String>> rowTitles,List<List<String>> colTitles,String fillToNull){
		
	
		
		List<List<String>> viewResult = new ArrayList<List<String>>() ;
		
		List<String> tmpRow = new ArrayList<String>() ;
		if(colTitles != null && colTitles.size() > 0){
			
			tmpRow.add("") ;
			
			for(List<String> colTitle : colTitles){
				tmpRow.add(colTitle.get(0)) ;
			}
			
			viewResult.add(tmpRow) ;
		}
		
		for(List<String> rowTitle : rowTitles){
			tmpRow = new ArrayList<String>() ;
			tmpRow.add(rowTitle.get(0)) ;
			
			for(List<String> colTitle : colTitles){
				
				String tmpValue = "" ;
				
				for(List<String> result : results){
					if(result.get(0).equals(rowTitle.get(0)) && result.get(1).equals(colTitle.get(0))){
						tmpValue = result.get(2) ;
					}
				}
				if("".equals(tmpValue))tmpValue = fillToNull ;
				
				tmpRow.add(tmpValue) ;
			}
			
			viewResult.add(tmpRow) ;
		}
		
		
		return viewResult ;
	}
	
	public static String dateType(String dateColumnName,Integer dateType){
		switch(dateType){
		case 0 :
			return "convert(varchar(4),"+dateColumnName+",120)" ;//年
		case 1 : 
			return "convert(varchar(7),"+dateColumnName+",120)" ;//月
		default :
			return "convert(varchar(4),"+dateColumnName+",120)" ;//年
		}
	}
	
	public static List<List<String>> monthList(String year){
		
		List<List<String>> result = new ArrayList<List<String>>() ;
		
		for(int i = 1 ; i <= 12 ; i++){
			List<String> item = new ArrayList<String>() ;
			
			String value = String.valueOf(i) ;
			if(value.length() == 1)value = "0" + value ;
			item.add(year + "-" + value) ;
			result.add(item) ;
		}
		
		return result ;
	}
}
